package com.iscale.controller;

import com.iscale.event.OrderEffectEvent;
import com.iscale.model.dto.Pager;
import com.iscale.model.entity.BaseRegionInfo;
import com.iscale.model.entity.SysUser;
import com.iscale.service.BaseRegionInfoService;
import com.iscale.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.iscale.controller.BaseController;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 * 区域信息 前端控制器
 * </p>
 *
 * @author Andychen
 * @since 2017-03-08
 */
@Api(value = "区域管理模块",description = "区域管理模块")
@Controller
@RequestMapping("/baseRegionInfo")
public class BaseRegionInfoController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(BaseRegionInfoController.class);

    @Autowired
    BaseRegionInfoService regionInfoService;

    @ApiOperation(value = "获取所有省信息", httpMethod = "POST", produces = "application/json", response = Result.class)
//    @RequiresPermissions("user:insert")
    @ResponseBody
    @RequestMapping(value = "getAllProvinces", method = RequestMethod.POST)
    public Result getAllProvinces() throws Exception {
        List<BaseRegionInfo> list = regionInfoService.getAllProvinces();

        return Result.success(list);
    }

    @ApiOperation(value = "初始化数据库省市区信息", httpMethod = "POST", produces = "application/json", response = Result.class)
//    @RequiresPermissions("user:insert")
    @ResponseBody
    @RequestMapping(value = "initRegionInfoByQQ", method = RequestMethod.POST)
    public Result initRegionInfoByQQ() throws Exception {
        regionInfoService.initRegionInfoByQQ();
        return Result.success("");
    }

    @ApiOperation(value = "根据id获取区域信息", httpMethod = "POST", produces = "application/json", response = Result.class)
//    @RequiresPermissions("user:insert")
    @ResponseBody
    @RequestMapping(value = "getRegionById", method = RequestMethod.POST)
    public Result getRegionById(@ApiParam(value = "区域ID", required = false) @RequestParam(defaultValue = "", required = true) String id) throws Exception {
        return Result.success(regionInfoService.getRegionById(id));
    }


    @ApiOperation(value = "查询子区域信息", httpMethod = "POST", produces = "application/json", response = Result.class)
//    @RequiresPermissions("user:insert")
    @ResponseBody
    @RequestMapping(value = "getSubRegionsByPid", method = RequestMethod.POST)
    public Result getSubRegionsByPid(@ApiParam(value = "父区域ID", required = false) @RequestParam(defaultValue = "", required = true) String pid) throws Exception {
       List<BaseRegionInfo> list = regionInfoService.getSubRegionsById(pid);
        return Result.success(list);
    }
}
